<template>
    <a-modal v-model:open="visible" title="添加已有用户" :destroy-on-close="destroyOnClose" width="1100px" :mask-closable="maskClosable" @cancel="close" @ok="handleSubmit">
        <SelectUser ref="selectUserRef" />
    </a-modal>
</template>
<script setup>
import { ref, nextTick } from 'vue'
import { useModal } from '@iframe/tools/mixins/ModelDrawerMixins'
import { add } from '/@/api/System/Team/User'
import SelectUser from './SelectUser.vue'
import { notice } from '@iframe/tools/components'
import { SUCCESS_CODE } from '@iframe/tools/axios/axios'

const { visible, destroyOnClose, maskClosable, close } = useModal()
const selectUserRef = ref()

const emits = defineEmits(['close'])
const open = teamId => {
    visible.value = true
    nextTick(() => {
        selectUserRef.value.setTeamId(teamId)
        selectUserRef.value.handleRefresh()
    })
}
const handleSubmit = () => {
    const selectKeys = selectUserRef.value.getSelectUsers()
    if (!selectKeys || selectKeys.length < 1) {
        notice.warning('请选择用户')
    }
    add(selectUserRef.value.getTeamUserParams()).then(result => {
        if (result.code === SUCCESS_CODE) {
            notice.success('添加成功')
            emits('close')
            visible.value = false
        }
    })
}
defineExpose({ open })
</script>
